package cn.lg.soar.system.auth.model;

import cn.lg.soar.common.util.BeanCopier;
import cn.lg.soar.core.annotations.constraints.group.Create;
import cn.lg.soar.core.annotations.constraints.group.Update;
import cn.lg.soar.system.auth.entity.TemporaryPassword;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.time.LocalDateTime;

/**
 * 临时密码
 * @author luguoxiang
 * @date 2021/9/12
 * 开源项目：https://gitee.com/lgx1992/lg-soar 求star！请给我star！请帮我点个star！
 */
@Getter
@Setter
public class TemporaryPasswordVo {

    public final static BeanCopier<TemporaryPasswordVo, TemporaryPassword> TO_ENTITY = BeanCopier.create(TemporaryPasswordVo.class, TemporaryPassword.class);
    public final static BeanCopier<TemporaryPassword, TemporaryPasswordVo> FROM_ENTITY = BeanCopier.create(TemporaryPassword.class, TemporaryPasswordVo.class);

    @NotNull(message = "id不能为空", groups = Update.class)
    private Long id;

    @NotBlank(message = "密码不能为空", groups = Create.class)
    @JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
    @ApiModelProperty("临时密码")
    private String password;

    @ApiModelProperty("有效期，为空表示不限")
    private LocalDateTime expires;

    @ApiModelProperty("最多允许次数，0表示不限")
    private Integer maxCount;

    @JsonProperty(access = JsonProperty.Access.READ_ONLY)
    @ApiModelProperty("已使用次数")
    private Integer usageCount;

    @ApiModelProperty("备注")
    private String remark;

    @JsonProperty(access = JsonProperty.Access.READ_ONLY)
    @ApiModelProperty("最近一次登录时间")
    private LocalDateTime lastLoginDate;

    @JsonProperty(access = JsonProperty.Access.READ_ONLY)
    @ApiModelProperty("更新时间")
    private LocalDateTime updateTime;

    @JsonProperty(access = JsonProperty.Access.READ_ONLY)
    @ApiModelProperty("创建时间")
    private LocalDateTime createTime;

    public TemporaryPasswordVo() {
    }

    public TemporaryPasswordVo(TemporaryPassword data) {
        FROM_ENTITY.copy(data, this);
    }

    public TemporaryPassword toTemporaryPassword() {
        return TO_ENTITY.convert(this);
    }
}
